<?php

namespace App\Jobs;

use DB;
use App\Jobs\Job;
use Carbon\Carbon;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Mail\Mailer;

class SendReminderEmail extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels, Queueable;
    protected $user;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(User $user)
    {
        $this->user = $user;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(Mailer $mailer)
    {
        // $mailer->send('emails.reminder', ['user'=>$user], function($m){
        //     $m->to('1341219953@qq.com');
        //     $m->subject('队列测试邮件');
        // });
        $times = $this->attempts();
        echo '队列任务执行。。';
        DB::table('testc')->insert(['uid'=>5, 'selltime'=>Carbon::now()]);
    }

    /**
     * 任务失败时执行
     * @return void
     */
    public function failed()
    {
        echo '任务失败了。。。';
    }
}
